package org.sanmao.wyj.controller.utils;

import org.sanmao.wyj.exception.TokenIsNullException;
import org.sanmao.wyj.exception.TokenOutTimeException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//作为SpringMVC的异常处理器
@RestControllerAdvice
public class ExceptionAdvice {

//    拦截所有的异常信息
    @ExceptionHandler
    public Result doException(Exception ex){
        ex.printStackTrace();
        return Result.failure(40001,"服务器开小差了，请联系管理员！");
    }

    @ExceptionHandler
    public Result tokenIsNullException(TokenIsNullException tokenException){
        tokenException.printStackTrace();
        return Result.failure_NoToken();
    }

    @ExceptionHandler
    public Result tokenOutTimeException(TokenOutTimeException tokenException){
        tokenException.printStackTrace();
        return Result.failure_TokenOutTime();
    }
}
